const mongoose = require('mongoose')

// const mongoDB = 'mongodb://localhost:27017/backend'
const mongoDB = 'mongodb://192.168.2.188:27017/backend'

mongoose.Promise = global.Promise

mongoose.connect(mongoDB, {
  useNewUrlParser: true,
  useUnifiedTopology: true,
  useFindAndModify: false
})

// 取得默认连接
const db = mongoose.connection
// 监听连接成功或失败
db.on('connected', () => {
  console.log('mongodb数据库连接成功')
}).on('error', () => {
  console.log('MongoDB 连接错误')
})

module.exports = mongoose
